package com.bj.dz.service.impl;

import com.bj.dz.entity.GasnetworkDataformat;
import com.bj.dz.mapper.GasnetworkDataformatMapper;
import com.bj.dz.service.GasnetworkDataformatService;
import com.bj.dz.util.Constants;
import com.bj.dz.util.EmptyUtils;
import com.bj.dz.util.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class GasnetworkDataformatServiceImpl implements GasnetworkDataformatService {

    @Resource
    private GasnetworkDataformatMapper gasnetworkDataformatMapper;

    public GasnetworkDataformat getGasnetworkDataformatById(Integer id){
        return gasnetworkDataformatMapper.getGasnetworkDataformatById(id);
    }

    public List<GasnetworkDataformat>	getGasnetworkDataformatListByMap(Map<String,Object> param){
        return gasnetworkDataformatMapper.getGasnetworkDataformatListByMap(param);
    }

    public Integer getGasnetworkDataformatCountByMap(Map<String,Object> param){
        return gasnetworkDataformatMapper.getGasnetworkDataformatCountByMap(param);
    }

    @Transactional
    public boolean addGasnetworkDataformat(GasnetworkDataformat gasnetworkDataformat){
            return gasnetworkDataformatMapper.insertGasnetworkDataformat(gasnetworkDataformat)>0?true:false;
    }

    @Transactional
    public boolean modifyGasnetworkDataformat(GasnetworkDataformat gasnetworkDataformat){
        return gasnetworkDataformatMapper.updateGasnetworkDataformat(gasnetworkDataformat)>0?true:false;
    }

    @Transactional
    public boolean deleteGasnetworkDataformatById(Integer id){
        return gasnetworkDataformatMapper.deleteGasnetworkDataformatById(id)>0?true:false;
    }

    public Page<GasnetworkDataformat> queryGasnetworkDataformatPageByMap(Map<String,Object> param, Integer pageNo, Integer pageSize){
        Integer total = gasnetworkDataformatMapper.getGasnetworkDataformatCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<GasnetworkDataformat> gasnetworkDataformatList = gasnetworkDataformatMapper.getGasnetworkDataformatListByMap(param);
        page.setRows(gasnetworkDataformatList);
        return page;
    }

}
